package cn.always.xiajia.framework.rpc.core.fegin;

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClientsProperties;
import org.springframework.cloud.client.loadbalancer.reactive.ReactiveLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;

/**
 * 多个服务可以根据标识负载均衡服务
 * 
 * @author xgj
 *
 */
public class RfqLoadBalancerClientFactory extends LoadBalancerClientFactory {

	public RfqLoadBalancerClientFactory(LoadBalancerClientsProperties properties) {
		super(properties);
	}

	@Override
	public ReactiveLoadBalancer<ServiceInstance> getInstance(String serviceId) {
		ReactiveLoadBalancer<ServiceInstance> reactiveLoadBalancer = super.getInstance(serviceId);
		// 参考 {@link
		// com.alibaba.cloud.nacos.loadbalancer.NacosLoadBalancerClientConfiguration#nacosLoadBalancer(Environment,
		// LoadBalancerClientFactory, NacosDiscoveryProperties)} 方法
		return new RfqLoadBalancerClient(super.getLazyProvider(serviceId, ServiceInstanceListSupplier.class), serviceId,
				reactiveLoadBalancer);
	}
}
